import { ReactNode } from "react";
import { useImmerReducer } from "use-immer";
import { TasksContext, TasksDispatchContext, initialTodos, taskReducer } from "./TasksContext";

interface TasksProviderProps {
  children: ReactNode;
}
function TasksProvider({ children }: TasksProviderProps) {
  const [todos, dispatch] = useImmerReducer(taskReducer, initialTodos);

  return (
    <TasksContext.Provider value={todos}>
      <TasksDispatchContext.Provider value={dispatch}>{children}</TasksDispatchContext.Provider>
    </TasksContext.Provider>
  );
}

export default TasksProvider;
